/*
 * @Author: xiaoyangzhao
 * @Date:   2018-04-19 17:21:57
 * @Last Modified by:   xiaoyangzhao
 * @Last Modified time: 2019-08-06 16:29:29
 */

import request from '@/utils/request'
import { route_origins, route_path_get } from '@/api/routes'
// import { callLogOut } from '@/api/call'
// import * as callSocket from '@/views/taskList/callDeskTop'

/**
 * [overdueLogin 登录携带ic和ui]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export function overdueLogin(params) {
  return request({
    url: route_origins + route_path_get + 'validateLogin',
    method: 'get',
    params
  })
}

/**
 * [login 登录]
 * @param  {String} username  [用户名称]
 * @param  {String} password  [密码]
 * @param  {String} imageCode [图形验证码]
 * @return {Function}         [异步接口方法]
 */
export function login(username, password, imageCode) {
  // callLogOut()
  return request({
    // url: route_origins + route_path_get + 'login',
    url: route_origins + route_path_get + 'login',
    method: 'post',
    // timeout: 1e3 * 60 * 30,
    data: {
      username,
      password,
      imageCode,
      ajax: 'XMLHttpRequest'
    }
  })
}

/**
 * [imgCaptcha 图形验证码]
 * @param  {Object} param     [description]
 * @return {Function}         [异步接口方法]
 */
export function imgCaptcha(param) {
  return request({
    // url: 'http://echo-star-dev4.zhichengcredit.com/jcaptcha?' + Date.now(),
    url: route_origins + route_path_get + 'jcaptcha?' + Date.now(),
    method: 'get',
    responseType: 'stream',
    param
  })
}

/**
 * [getInfo 获取用户信息]
 * @param  {Array} token  [用户角色口令]
 * @return {Function}     [异步接口方法]
 */
export function getInfo(token) {
  return request({
    url: route_origins + route_path_get + 'user/info',
    method: 'get',
    params: {
      token,
      ajax: 'XMLHttpRequest'
    }
  })
}

/**
 * [logout 登出]
 * @return {Function}     [异步接口方法]
 */
export function logout() {
  return request({
    url: route_origins + route_path_get + 'logout',
    method: 'get'
  })
}

/**
 * [userModifyPwd 重置密码]
 * @param  {Object} params [旧密码oldPassword/新密码newPassword]
 * @return {Function}      [异步接口方法]
 */
export function userModifyPwd(params) {
  return request({
    url: route_origins + route_path_get + 'user/modifyPwd',
    method: 'post',
    params
  })
}

/**
 * [userResetPwd 重置密码]
 * @param  {Object} params [旧密码oldpassword/新密码newpassword]
 * @return {Function}      [异步接口方法]
 */
export function userResetPwd(params) {
  return request({
    url: route_origins + route_path_get + 'user/resetPwd',
    method: 'post',
    params
  })
}

/**
 * [userTodo 首页 待办事项]
 * @return {Function}     [异步接口方法]
 */
export function userTodo(params) {
  return request({
    url: route_origins + route_path_get + 'user/todo',
    method: 'get',
    params
  })
}

/**
 * [reportCoverHome 首页 覆盖率报表数据]
 * @return {Function}     [异步接口方法]
 */
export function reportCoverHome(params) {
  return request({
    url: route_origins + route_path_get + 'report/cover/query/home',
    method: 'get',
    params
  })
}

/**
 * [reportAvgEfficiencyHome 首页 首页平均处理时效数据]
 * @return {Function}     [异步接口方法]
 */
export function reportAvgEfficiencyHome(params) {
  return request({
    url: route_origins + route_path_get + 'report/avg_efficiency/query/home',
    method: 'get',
    params
  })
}
